package com.example.zluserservice.framework.mq.producer;

/**
 * @Author zhenliu（孙凌岳）
 * @Description 操作日志发送器，用于将用户操作发送到MQ
 * @Date 2025/6/19 15:09
 * @Version 1.0
 */

import com.example.zluserservice.framework.mq.message.OperationLogMessage;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import java.util.Date;

@Component
@RequiredArgsConstructor
public class OperationLogProducer {

    private final RabbitTemplate rabbitTemplate;

    //和日志服务约定的交换机、路由键
    private static final String EXCHANGE_NAME = "log.exchange";
    private static final String ROUTING_KEY = "log.routing";

    public void send(OperationLogMessage operationLogMessage) {
        rabbitTemplate.convertAndSend(EXCHANGE_NAME, ROUTING_KEY, operationLogMessage);
    }

//    /**
//     * 封装构建并发送日志
//     * @param userId
//     * @param username
//     * @param action
//     * @param url
//     * @param ip
//     * @param detail
//     * @param status
//     * @param operTime
//     */
//    public void sendLog(Long userId, String username, String action, String url, String ip, String detail, int status, Date operTime) {
//        OperationLogMessage logMessage = OperationLogMessage.builder()
//                .userId(userId)
//                .username(username)
//                .action(action)
//                .url(url)
//                .ip(ip)
//                .detail(detail)
//                .status(status)
//                .operTime(operTime)
//                .build();
//        send(logMessage);
//    }
}
